'use strict';

const Controller = require('egg').Controller;

class UserController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = {
      id: ctx.params.userId,
      username: 'text',
    };
  }

  async api() {
    const { ctx } = this;
    ctx.body = 'Day 02';
  }

  async getFollowers() {
    const { ctx } = this;
    ctx.body = await ctx.service.github.getFollowers(ctx.query);
  }

  async getUserList() {
    const { ctx } = this;
    const { data: { list } } = await ctx.service.github.getFollowers(ctx.query);
    console.log(list);
    await ctx.render('list', { list });
  }

  async testPlugin() {
    const { ctx } = this;
    // 测试自定义的 context 扩展插件（数组去重）
    ctx.body = await ctx.dedupArray([ 1, 1, 3, 5 ]);
  }

}

module.exports = UserController;
